<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item label="文件名" prop="fileName">
                <el-input v-model="queryParams.fileName" placeholder="请输入文件名" clearable size="mini"
                          @keyup.enter.native="handleQuery"/>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
          <el-tab-pane label="客服" name="1"/>
          <el-tab-pane label="保洁" name="2"/>
          <el-tab-pane label="秩维" name="3"/>
          <el-tab-pane label="安保" name="4"/>
          <el-tab-pane label="消防" name="5"/>
          <el-tab-pane label="设备" name="6"/>
          <el-tab-pane label="违法违规行为" name="7"/>
          <el-tab-pane label="会议记录" name="8"/>
        </el-tabs>

        <el-table v-loading="loading" :data="downloadList" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="55" align="center" />
                    <el-table-column label="文件名" align="center" prop="fileName" />
<!--                    <el-table-column label="文件地址" align="center" prop="fileUrl" />-->
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="importDownload(scope.row)"
                               v-hasPermi="['system:download:edit']">下载</el-button>

                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0"
                    :total="total"
                    :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList" />

    </div>
</template>

<script>
    import { listDownload, getDownload, delDownload, addDownload, updateDownload, exportDownload } from "@/api/module/fileDownload/download";

    export default {
        name: "Download",
        data() {
            return {
              activeName:"1",
                // 按钮loading
                buttonLoading: false,
                // 遮罩层
                loading: true,
                // 导出遮罩层
                exportLoading: false,
                // 选中数组
                ids: [],
                // 非单个禁用
                single: true,
                // 非多个禁用
                multiple: true,
                // 显示搜索条件
                showSearch: true,
                // 总条数
                total: 0,
                // 企管类相关资料格表格数据
                    downloadList: [],
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 查询参数
                queryParams: {
                    pageNum: 1,
                    pageSize: 10,
                    fileType:1,
                },
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                }
            }
        },
        created() {
            this.getList();
        },
        methods: {
            /** 查询企管类相关资料格列表 */
            getList() {
                this.loading = true;
                listDownload(this.queryParams).then(response => {
                    this.downloadList = response.rows;
                    this.total = response.total;
                    this.loading = false;
                });
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                        id: undefined,
                        fileName: undefined,
                        fileUrl: undefined,
            }
                this.resetForm("form");
            },
            /** 搜索按钮操作 */
            handleQuery() {
                this.queryParams.pageNum = 1;
                this.getList();
            },
            /** 重置按钮操作 */
            resetQuery() {
                this.resetForm("queryForm");
                this.handleQuery();
            },
            // 多选框选中数据
            handleSelectionChange(selection) {
                this.ids = selection.map(item => item.id);
                this.single = selection.length!==1;
                this.multiple = !selection.length;
            },

            /** 删除按钮操作 */
            handleDelete(row) {
                const ids = row.id || this.ids;
                this.$confirm('是否确认删除企管类相关资料格编号为"' + ids + '"的数据项?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(() => {
                    this.loading = true;
                    return delDownload(ids);
                }).then(() => {
                    this.loading = false;
                    this.getList();
                    this.msgSuccess("删除成功");
                }).catch(() => {});
            },
          handleClick(val){
            console.log('handleClick',val.name);
            this.activeName = val.name;
            this.queryParams.fileType = parseInt(val.name);
            this.getList();
          },
          /** 下载模板操作 */
          importDownload(row) {
            window.location.href = "https://www.caihengyun.com/chyimg/file/temp/office/"+this.activeName+"/"+row.fileUrl+"."+row.format;
            },

        }
    };
</script>
